import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Scanner;

public class Homework01 {
    public void copy() {
        FileInputStream fis = null;
        FileOutputStream fos = null;
        try {
            fis = new FileInputStream("C:/a.txt");
            int d = 0;
            byte[] bytes = new byte[1024];
            while ((d = fis.read(bytes)) != -1) {
                fos.write(bytes, 0, d);
            }
            fos.flush();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (fis != null) {
                try {
                    fis.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }

    public void append() {
        Scanner scan = new Scanner(System.in);
        System.out.println("输入一串字符");
        String str = scan.next();
        FileOutputStream fos = null;
        try {
            fos = new FileOutputStream("C:/a.txt", true);
            fos.write(str.getBytes());
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (fos != null) {
                try {
                    fos.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }

    public static void main(String[] args) {
        Homework01 homework01 = new Homework01();
        homework01.copy();

    }
}
